#pragma once

#include "OpenGL.h"
#include "pgObjects.h"

#include <vector>
#include <string>

using namespace std;

#define OFFSET(i) ((char*)NULL + i)

// data structures -----------------

struct vtxData
{
	float x, y, z;
	float nx, ny, nz;
	float u, v;
};

struct vtx
{
	float x, y, z;
};

struct nml
{
	float nx, ny, nz;
};

struct tex
{
	float u, v;
};

// --------------------------------

//TODO: clear the data after uploading to gfx memory
//		delete vbos in the destructor

class PlayerShip : public pgObjects
{
public:
	enum
	{
		BODYPART_CHASSIS = 0,
		BODYPART_COUNT
	};

	enum
	{
		JOINT_COUNT = 0
	};

	PlayerShip();
	PlayerShip(btVector3 const & pos);

	//initGFX
	void loadGeometry(char const * file_name = "models\\tri_mare.obj");

	~PlayerShip(); //destroy the VBO here and free memory;

	void initVBO();
	void drawGeometry(GLuint render_mode);
	
	int getPolyCount() const { return polyCount; }

	//physics members
	btDynamicsWorld* m_ownerWorld;
	btCollisionShape* m_shapes[BODYPART_COUNT];
	btRigidBody* m_bodies[BODYPART_COUNT];
	//btTypedConstraint* m_joints[JOINT_COUNT];

	static btAlignedObjectArray<class SpaceShip*> m_spaceships;
	static void deleteAllSpaceShips();

	void setObjectState(int state);

private:
	vector<string> break_input(string const &);

	bool updated;
	int polyCount;

	vector<vtxData> data;
	
	vector<vtx> vtx_array;
	vector<nml> nml_array;
	vector<tex> tex_array;

	GLuint vboID;
};